package com.hxm.gestures;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;

/**
 * Created by HXM on 2016/9/8.
 * Description:
 */
public class SimpleGestureActivity extends AppCompatActivity {
    private final String TAG = "Gesture";
    private GestureDetectorCompat detectorCompat;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_gesture);
        detectorCompat = new GestureDetectorCompat(this, new MyGesture());
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        this.detectorCompat.onTouchEvent(event);
        return super.onTouchEvent(event);
    }

    class MyGesture extends GestureDetector.SimpleOnGestureListener {
        @Override
        public boolean onDown(MotionEvent e) {
            Log.i(TAG, "onDown");
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            Log.i(TAG, "onDoubleTap");
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            Log.i(TAG, "onFling");
            startActivity(new Intent(SimpleGestureActivity.this, MainActivity.class));
            return true;
        }
    }
}
